how to count occurrences of a character in a string